﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

// T.R.A.C.
// Main Author: Morgan Davis
// Additional Authors:
// Date: 10/20/2013

namespace TRAC_Demo
{
    public partial class FormAgentList : Form
    {
        #region [ Fields ]

        public string returnAgent { get { return comboAgents.Text; } }
        TRACobjectsDataContext DB = new TRACobjectsDataContext();

        #endregion

        #region [ Constructors ]

        public FormAgentList()
        {
            InitializeComponent();
            this.BackColor = CurrentUser.UserColor;
            this.ControlBox = false;

            //run query to gather all available agents from the database
            var AgentQuery = from emp in DB.Agents orderby emp.lName select emp;

            //populate drop down with all available agents
            foreach (var agt in AgentQuery)
            {
                comboAgents.Items.Add(agt.EmployeeID.ToString().PadRight(5)
                    + ": " + agt.lName + ", " + agt.fName);
            }
        }

        #endregion

        #region [ Events ]

        public FormAgentList(bool orderBy) //overloaded method that returns list of agents ordered
                                           //by number rather than by last name
        {
            InitializeComponent();
            this.ControlBox = false;
            var AgentQuery = from emp in DB.Agents select emp;
            foreach (var agt in AgentQuery)
            {
                comboAgents.Items.Add(agt.EmployeeID.ToString().PadRight(5)
                    + ": " + agt.lName + ", " + agt.fName);
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (comboAgents.Text == "") //do not allow return of 'OK' without making a selection
                this.DialogResult = DialogResult.Cancel;
            else
                this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e) //close form and return 'CANCEL'
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        #endregion
    }
}
